<?php if (!defined('THINK_PATH')) exit();?>﻿<!DOCTYPE html>
<html class="wh100">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
		<title><?php echo C('WEB_SITE_TITLE');?></title>
		<link rel="stylesheet" href="/FQMALL_v1.1.1/Public/Home/css/common.css">
		<link rel="stylesheet" href="/FQMALL_v1.1.1/Public/Home/css/main.css" />
		<script src="/FQMALL_v1.1.1/Public/Home/js/zepto.js"></script>
		<script src="/FQMALL_v1.1.1/Public/Home/js/iscroll-probe.js"></script>
		<script src="/FQMALL_v1.1.1/Public/Home/js/delIOS_huitan.js"></script>
		<?php
require_once "./sample/php/jssdk.php"; $jssdk = new JSSDK("wx73f8f21829bef9c6", "00ea7e3072f302d457e88b7402dc6429"); $signPackage = $jssdk->GetSignPackage(); ?>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript">
	wx.config({
			      debug: false,
			      appId: '<?php echo $signPackage["appId"];?>',
			      timestamp: <?php echo $signPackage["timestamp"];?>,
			      nonceStr: '<?php echo $signPackage["nonceStr"];?>',
			      signature: '<?php echo $signPackage["signature"];?>',
			      jsApiList: [
			        'checkJsApi',
			        'onMenuShareTimeline',
			        'onMenuShareAppMessage',
			        'onMenuShareQQ',
			        'onMenuShareWeibo',
			        'onMenuShareQZone',
			      ]
			  });
			
		wx.ready(function(){
			var weiurl = "<?php echo ($weiurl); ?>";
			var weilink = window.location.href;
			var weititle = "<?php echo C('WEB_SITE_TITLE');?>";
			var imgurl = "http://www.miguaner.cn/Public/share/img/chanmaologo.png";
			console.log(weiurl);
	        wx.checkJsApi({
	            jsApiList: ['onMenuShareAppMessage'], // 需要检测的JS接口列表，所有JS接口列表见附录2,
	        });
	         wx.onMenuShareTimeline({
	            title: weititle, 
	            link: weiurl,
	            imgUrl: imgurl, // 分享图标
	            trigger:function(res){
	            },
	            success: function () {
	                //alert('已分享');
	            },
	            cancel: function () {
	            },
	            fail:function(){
	            } 
	        });
	        wx.onMenuShareAppMessage({
	            title: weititle, // 分享标题
	            desc: weilink, // 分享描述
	            link: weiurl, // 分享链接
	            imgUrl: imgurl, // 分享图标
	            type: 'link', // 分享类型,music、video或link，不填默认为link
	            dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
	            success: function () {
	              //  alert('hello');
	            },
	            cancel: function () {
	            }
	        });
	         //分享到QQ
	        wx.onMenuShareQQ({
	            title: weititle,
	            desc: weilink,
	            link: weiurl,
	            imgUrl: imgurl, // 分享图标
	            success: function () { 
	               // 用户确认分享后执行的回调函数
	            },
	            cancel: function () { 
	               // 用户取消分享后执行的回调函数
	            }
	        });
	        //分享到腾讯微博
	        wx.onMenuShareWeibo({
	            title: weititle,
	            desc: weilink,
	            link: weiurl,
	            imgUrl: imgurl, // 分享图标
	            success: function () { 
	               // 用户确认分享后执行的回调函数
	            },
	            cancel: function () { 
	                // 用户取消分享后执行的回调函数
	            }
	        });

	        // 分享到qq空间
	        wx.onMenuShareQZone({
			    title: weititle, // 分享标题
			    desc: weilink, // 分享描述
			    link: weiurl, // 分享链接
			    imgUrl: imgurl, // 分享图标
			    success: function () { 
			       // 用户确认分享后执行的回调函数
			    },
			    cancel: function () { 
			        // 用户取消分享后执行的回调函数
			    }
			});
    	});
</script>

		<style> 
			/*下拉加载样式*/
			#wrapper {
				position: absolute;
				z-index: 1;
				top: 0;
				bottom: 0;
				left: 0;
				width: 100%;
				overflow: hidden;
			}
			#loadBin{color: #5d5d5d;text-align: center;line-height: 30px;}
		</style>
	</head>
	<body class="wh100 box" onLoad="onload()">
		<!--遮罩层-->
		<div id="zhezhao" style="display:none"></div>
		<!--一开始隐藏在右侧的筛选框-->
		<div id="fenleiShaixuan" style="display: none;" class="fastscroll">
			<div class="top">
				<div class="contain maxWidth">
					<span class="hz back" onclick="javascript:hiddenonetwo()">&#xe600;</span>筛选
				</div>
			</div>
			<div class="main fastscroll">
				<div class="contain maxWidth">
					<!--一级界面 二级界面只显示一个-->
					<!--一级界面-->
					<div class="oneJi">
						<div class="price">
							<p class="title">按价格</p>
							<div class="content">
								<input type="text" class="low" placeholder="最低价" id="min_price"><span class="line">——</span><input type="text" class="high" placeholder="最高价" id="max_price">
							</div>
						</div>
						<div class="fenlei">
							<p class="title">
								<span>按分类</span>
								<em><!--用户选了这里才会有内容--></em>
							</p>
							<ul class="content">
							<?php if(is_array($onecatelist)): $i = 0; $__LIST__ = $onecatelist;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$item): $mod = ($i % 2 );++$i;?><li><a href="javascript:getsecondlist(<?php echo ($item["id"]); ?>);"><em><?php echo ($item["title"]); ?></em><span class="hz">&#xe60c;</span></a></li><?php endforeach; endif; else: echo "" ;endif; ?>
							</ul>
						</div>
					</div>
<input type="hidden" id="category_id" value="" />
<script>
function hiddenonetwo()
{
	$('#fenleiShaixuan').css('display','none');
	$('#zhezhao').css('display','none');
	$('#fenleiShaixuan').animate({
		'left':0
	},500,'ease',function(){
		//页面不许滚动
		$('#sousuoListMain').css('overflow-y','hidden');
	});
	//$('#fenleiShaixuan .main .twoJi').css('display','none');
}
function displayone(wenzi)
{
	//alert('d');
	$('#fenleiShaixuan .main .oneJi').css('display','block');
	$('#fenleiShaixuan .main .twoJi').css('display','none');
	//var wenzi=$(this).find('a').text();
	//alert(wenzi);
	$('#fenleiShaixuan .main .oneJi .fenlei .title em').text(wenzi);
}
function getsecondlist(category_id)
{
	$.ajax({
		//提交数据的类型 POST GET
		type:"POST",
		//提交的网址
		url:"/FQMALL_v1.1.1/index.php?s=/Home/Search/getsecondlist",
		//提交的数据
		data:{'category_id':category_id},
		//返回数据的格式
		datatype: "json",
		success:function(data){
			var str='<ul>';
			for(var i=0;i<data.length;i++)
			{
				str+='<li><a href="javascript:$(\'#category_id\').val('+data[i].id+');displayone(\''+data[i].title+'\')">'+data[i].title+'</a></li>';
			}
			str+='</ul>';
			$('#fenleiShaixuan .main .oneJi').css('display','none');
			$('.twoJi').html(str);
			$('.twoJi').css('display','block');
			//$('#twoJi').show();
			//$("#msg").html(decodeURI(data));            
		}
   });
}
function search()
{
	var url='/Search/index?keywords='+$('#keywords').val();
	window.location.href=url;
}
</script>
					<!--二级界面 一开始不显示-->
					<div class="twoJi" style="display: none">
						<ul>
						<!--
							<li><a href="javascript:;">豆浆机</a></li>
							<li><a href="javascript:;">电磁炉</a></li>
							<li><a href="javascript:;">电饭煲</a></li>
							<li><a href="javascript:;">榨汁机</a></li>
							<li><a href="javascript:;">养生壶</a></li>
							<li><a href="javascript:;">净水器</a></li>
							<li><a href="javascript:;">微波炉</a></li>
							<li><a href="javascript:;">电烤箱</a></li>
							<li><a href="javascript:;">电饼铛</a></li>
							<li><a href="javascript:;">面条机</a></li>
							<li><a href="javascript:;">咖啡机</a></li>
						-->
						</ul>
					</div>
				</div>
			</div>
			<div class="bot">
				<div class="contain maxWidth">
					<button class="reset">重置</button><button class="sure">确定</button>
				</div>
			</div>
		</div>
		<!--正文区域-->
		<div id="sousuoListTop"> 
			<div class="contain maxWidth clear">
				<div class="top1">
					<a class="hz back" href="/">&#xe600;</a>
					<div class="ssInputArea">
						<input type="text" id="keywords" placeholder="请输入要查询的产品名称" value="<?php echo ($keywords); ?>">
						<span class="hz search" onclick="search()">&#xe607;</span>
					</div>
				</div>
				<ul class="top2 clear">
					<li <?php if($order == 0): ?>class="active"<?php endif; ?>>
						<div>
							<a onclick="javascript:doOrder('zonghe');">
								<span class="title">综合</span>
								<p class="twoicon">
									<span class="hz up <?php if($desc == "asc" and $order == 0): ?>active<?php endif; ?>">&#xe60a;</span>
									<span class="hz down <?php if($desc == "desc" and $order == 0): ?>active<?php endif; ?>">&#xe608;</span>
								</p>
								<!-- <?php if($order == 0): ?><span class="hz zh">&#xe60b;</span><?php endif; ?> -->
							</a>
						</div>
					</li>
					<li <?php if($order == 1): ?>class="active"<?php endif; ?>>
						<div>
							<a onclick="javascript:doOrder('xiaoliang');">
								<span class="title">销量</span>
								<p class="twoicon">
									<span class="hz up <?php if($desc == "asc" and $order == 1): ?>active<?php endif; ?>">&#xe60a;</span>
									<span class="hz down <?php if($desc == "desc" and $order == 1): ?>active<?php endif; ?>">&#xe608;</span>
								</p>
								<!-- <?php if($order == 1): ?><span class="hz zh">&#xe60b;</span><?php endif; ?> -->
							</a>
						</div>
					</li>
					<li <?php if($order == 2): ?>class="active"<?php endif; ?>>
						<div class="price">
						<?php if($desc == 'asc'): ?><a onclick="javascript:doOrder('price');" >
						<?php else: ?>
							<a onclick="javascript:doOrder('price');" ><?php endif; ?>
								<span class="title">价格</span>
								<p class="twoicon">
									<span class="hz up <?php if($desc == "asc" and $order == 2): ?>active<?php endif; ?>">&#xe60a;</span>
									<span class="hz down <?php if($desc == "desc" and $order == 2): ?>active<?php endif; ?>">&#xe608;</span>
								</p>
							</a>
						</div>
					</li>
					<!-- <li>
						<div>
							<a href="javascript:;">
								<span class="title">筛选</span><span class="hz sx">&#xe609;</span>
							</a>
						</div>
					</li> -->
				</ul>
			</div>
		</div>

		
		<div id="sousuoListMain" class="fastscroll">
			<div class="contain maxWidth infinite-scroll infinite-scroll-bottom">
				<div id="wrapper" class="maxWidth">
					<div>
						<ul class="list">
							<?php if(is_array($list)): $i = 0; $__LIST__ = $list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$item): $mod = ($i % 2 );++$i;?><li>
								<a href="<?php echo U('Product/detail',array('id'=>$item['id']));?>">
									<div class="clear">
										<div class="left">
											<img src="<?php echo ($item["image"]); ?>">
										</div>
										<div class="right">
											<p class="title"><?php echo ($item["title"]); ?></p>
											<p class="price">
												<em>&yen;<?php echo ($item["gprice"]); ?></em><del>&yen;<?php echo ($item["market_price"]); ?></del>
											</p>
											<p class="peoplemai">已有<?php echo ($item["sell_num"]); ?>人购买</p>
											<span class="share"><span class="hz">&#xe60e;</span>分享</span>
										</div>
									</div>
								</a>
							</li><?php endforeach; endif; else: echo "" ;endif; ?>
						</ul>
						<div class="noData" style="display:none">没有更多数据了</div>
						<div id="loadBin">
							<?php
 if(empty($list)) { ?>
							您搜索的<?php echo ($keywords); ?>没有相关的产品
							<?php
 } ?>
						</div>
					</div>
				</div>
			</div>
		</div>


		<script>
			//返回按钮
			/*$('#sousuoListTop .back').on('click',function(){
				//window.history.go(-1);
				// location.href='<?php echo U('Index/Index');?>';
			});*/

			//小键盘弹出 底部不固定问题
			var oldWinHeight=window.innerHeight;
		    window.addEventListener('resize',function(){
		        if(window.innerHeight<oldWinHeight){
		        	//说明键盘出来了
		            oldWinHeight=window.innerHeight;
		            document.querySelector('#fenleiShaixuan .bot').style.position='static';
		            document.querySelector('#fenleiShaixuan .bot').style.marginTop='-100px';
		            document.querySelector('#fenleiShaixuan .main').style.bottom=0;
		        }
		        else if(window.innerHeight>oldWinHeight){
		        	//键盘收回去了
		            oldWinHeight=window.innerHeight;
		            document.querySelector('#fenleiShaixuan .bot').style.position='absolute';
		            document.querySelector('#fenleiShaixuan .bot').style.marginTop=0;
		            document.querySelector('#fenleiShaixuan .main').style.bottom='68px';
		        }
		    },false);

			//判断当前页面是正常进入，还是从分类界面 点击筛选进入的
			var hrefstr=location.href;
			if(hrefstr.indexOf('shaixuan=true')!=-1){
				//点击筛选进入的
				//直接打开侧边栏
				$('#fenleiShaixuan').css('display','block');
				$('#zhezhao').css('display','block');
				$('#fenleiShaixuan').animate({
					'left':0
				},500,'ease',function(){
					//页面不许滚动
					$('#sousuoListMain').css('overflow-y','hidden');
				});
			}

			//点击价格 切换箭头颜色
			$('#sousuoListTop .top2 li div.price').on('tap',function(){
				var oldColorUp=$(this).find('.up').css('color');
				var oldColorDown=$(this).find('.down').css('color');
				$(this).find('.up').css('color',oldColorDown);
				$(this).find('.down').css('color',oldColorUp);
			});

			function doOrder(order){
				var keywords = "<?php echo ($keywords); ?>";
				var desc = "<?php echo ($desc); ?>";
				var url = "<?php echo U('Search/index');?>";
				if(keywords!="") url += "&keywords="+keywords;
				if(order=='zonghe') url += "&order=0";
				if(order=='xiaoliang') url += "&order=1";
				if(order=='price') url += "&order=2";
				url += "&desc="+desc;
				location.href = url;
			}
			
			//点击顶部搜索
			$('#sousuoListTop .top1 .ssInputArea').on('tap',function(){
				location.href="<?php echo U('Search/pageindex');?>";
			});

			//iscroll 下拉加载+zeptoajax
			function onload(){
				loadBin = document.getElementById("loadBin");
				myScroll = new IScroll('#wrapper',{
					probeType: 3,
					click:true
				});
				myScroll.on("scroll",scrollFun);
				myScroll.on("scrollEnd",scrollEndFun);
			}
			var page=2,share="<?php echo ($share); ?>",keywords="<?php echo ($keywords); ?>",category="<?php echo ($category_id); ?>",min_price="<?php echo ($min_price); ?>",max_price="<?php echo ($max_price); ?>",order="<?php echo ($order); ?>",desc="<?php echo ($desc); ?>";
			var page=2;
			var myScroll,
				loadBin,
				isload = false,
				scrollFun = function(){
					if((this.y - this.maxScrollY)>>0 < -50){
						isload = true;
						loadBin.innerHTML = "松开手指加载更多";
						myScroll.refresh();
						myScroll.off("scroll",scrollFun);
					}
				},
				scrollEndFun = function(){
					if(isload){
						isload = false;
						
						 $.ajax({
						 	type: 'POST',
						 	url: "<?php echo U('ajaxPage');?>",
						 	dataType: 'json',
							data:{page:page,keywords:keywords,category_id:category,min_price:min_price,max_price:max_price,order:order,desc:desc},
						 	success: function(data){
						 		if(data!=""){
							 		page++;
	
									var str='';
									for(var i=0;i<data.length;i++){
										str+='<li>\
												<a href="/index.php?s=/Product/detail/id/'+data[i].id+'.html">\
													<div class="clear">\
														<div class="left">\
															<img src="'+data[i].image+'">\
														</div>\
														<div class="right">\
															<p class="title">'+data[i].title+'</p>\
															<p class="price">\
																<em>&yen;'+data[i].gprice+'</em><del>&yen;'+data[i].market_price+'</del>\
															</p>\
															<p class="peoplemai">已有'+data[i].buyer_num+'人购买</p>\
															<span class="share"><span class="hz">&#xe60e;</span>分享</span>\
														</div>\
													</div>\
												</a>\
											</li>';
									}
									$('#sousuoListMain .list').append(str);
									
									loadBin.innerHTML = "";
									myScroll.on("scroll",scrollFun);
									myScroll.refresh();
						 		}else{
						 			//显示没有更多数据了
									$('.noData').css('display','block');
									loadBin.innerHTML = "";
									//没有必要再看到 松开手指加载更多
									scrollFun = function(){
										loadBin.innerHTML = "";
										myScroll.refresh();
										myScroll.off("scroll",scrollFun);
									}
						 		}
						 	},
						 	error: function(xhr, type){
						 		console.log('Ajax error!');
						 	}
						 });
					}
				};
		</script>
	</body>
</html>